﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:include="inc/home::header">

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" th:src="@{/home/js/public.js}"></script>
<script type="text/javascript" >  

function validatePassword(){
	var patrn= /^.*(?=.{10,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z]).*$/;
	var pwd = $("#password").val();
	if(!(patrn.test(pwd))){
		$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">密码长度需大于10,并至少1个大写字母，1个小写字母，1个数字组成。!</div></div>', {
            'title':'提示',
            'buttons':['确定']
         });
		return false;
	}else{
		return true;
	}
}	

</script>
</head>
<body>
	    <div class="project">  
	          <div class="project-view" style="margin-top:20px">
	           	<form id="passwordForm">
				<table width="80%" align="center" cellpadding="0" cellspacing="0">
				  <tr>
					<td width="20%" align="right"><span class="color-red">*</span>旧密码：</td>
					<td width="60%"><input type="password" class="input-pub"   name="userPassword"   id="userPassword"/></td>
				  </tr>
			
				  <tr>
    <td align="right"><span class="color-red">*</span>新密码&nbsp;</td>
    <td><input id="password" name="password" type="password"  class="input-pub" onblur="validatePassword()"/></td>
</tr>
<tr>
    <td align="right"><span class="color-red">*</span>确认密码&nbsp;</td>
    <td><input  id="confirmPassword"  type="password" class="input-pub"  name="confirmPassword"  /></td>
</tr>		</table>
				</form>
			</div>
	        <!--内容结束-->
	    </div>
	</body>
	
<script th:inline="javascript">  
/*<![CDATA[*/  
    function getDataJson(formId) {
    var dataJson = {};
    $("#"+formId).serializeArray().map(function (x) {
        if (dataJson[x.name] !== undefined) {
            if (!dataJson[x.name].push) {
                dataJson[x.name] = [dataJson[x.name]];
            }
            dataJson[x.name].push(x.value || '');
        } else {
            dataJson[x.name] = x.value || '';
        }
    });

    return dataJson;
}	

 function passwordReset() {
	 var result;
		var validate=getData();
		  if(!validate){
			 return false;
		 }
        var password = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        
		if(!confirmPassword || confirmPassword.length < password.length){
			return;
		}
 
        if (password != confirmPassword){
			 top.$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">两次密码不一致!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
            document.getElementById("confirmPassword").focus();
            return;
        }
		var obj=getDataJson("passwordForm");
		 $.ajax({
		     type: "post",
		     dataType: "json",
		     async:false,
		     url:"/Password/passwordReset" ,
		     data:obj,
		     success: function (data, status) {
		    	 result=data;
		     },
		     error: function (data) {
		   
		     }
		 });
		 
		 
	return result;	 
		 
		 
 };
	  function verifyNull(obj){
			
			if(obj == null||obj.val()==""||obj.val()=="请选择"){
				top.$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">输入的内容不能包含空</div></div>', {
					'title':'提示',
		 	         'buttons':['确定']
			     });
				return false;
			}
		return true;
	}      
	 function getData(){
		if(!verifyNull($("#userPassword"))){
	 		return false;
	 	}
		if(!verifyNull($("#password"))){
	 		return false;
	 	}
		if(!verifyNull($("#confirmPassword"))){
	 		return false;
	 	}
		return true;
	 }
		

/*]]>*/  
</script>
	
	
</html>
